coretool fixes and enhancements (#921)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Tue, 20 Sep 2022 18:03:33 +0000 (12:03 -0600)
committerGitHub <noreply@github.com>
Tue, 20 Sep 2022 18:03:33 +0000 (12:03 -0600)
* get coretool to work on macos under qmake.

* enhance coretool.

1. don't use stderr for coretool output.  This avoids comingling of
real error messages with the coretool output.
2. disable the similartext heuristic with coretool.  This heuristic,
which is enabled by default, was resulting in occasional mistranslations.

gui/coretool/coretool.cc
gui/coretool/coretool.pro
gui/formatload.cc

index fe562e3faa4a0018f1e6683e5fdbc763970924b3..3121cf18626615483aee09a39177ec31fdd07f83 100644 (file)
@@ -1,12 +1,36 @@
-#include <QList>
 #include <QApplication>
+#include <QFile>
+#include <QList>
+#include <QTextStream>
 
 #include "format.h"
 #include "formatload.h"
 
+QTextStream* generate_output_stream;
+
 int main(int argc, char** argv)
 {
   QApplication app(argc, argv);
+  QStringList qargs = QApplication::arguments();
+
   QList<Format> formatList;
-  return FormatLoad().getFormats(formatList) ? 0 : 1;
+
+  if (qargs.size() != 2) {
+    qFatal("Usage: %s output_file_name", qPrintable(qargs.at(0)));
+  }
+
+  QFile generate_output_file(qargs.at(1));
+  bool status = generate_output_file.open(QIODevice::WriteOnly);
+  if (!status) {
+    qFatal("Could not open %s for write!", qPrintable(qargs.at(1)));
+  }
+  generate_output_stream = new QTextStream(&generate_output_file);
+
+  bool fmtstatus = FormatLoad().getFormats(formatList);
+
+  generate_output_stream->flush();
+  generate_output_file.close();
+  delete generate_output_stream;
+
+  return fmtstatus ? 0 : 1;
 }
index abcc7bdc4cb81db7073e5c1a8bb9008400d439b9..459fe38ee24d2b70f9d0aff0f27c3f50100b8e6c 100644 (file)
@@ -4,6 +4,7 @@
 # these strings.
 #
 CONFIG += console
+CONFIG -= app_bundle
 
 QT -= gui
 QT += core \
@@ -29,13 +30,18 @@ core_strings.target = core_strings.h
 core_strings.depends = $(TARGET)
 core_strings.depends += ../../gpsbabel
 core_strings.commands = $(COPY_FILE) ../../gpsbabel $(DESTDIR)gpsbabel &&
-core_strings.commands += ./$(TARGET) 2>core_strings.h;
+core_strings.commands += ./$(TARGET) core_strings.h;
 QMAKE_EXTRA_TARGETS += core_strings
 QMAKE_DISTCLEAN += $(DESTDIR)gpsbabel
 
+# The line numbers are almost meaningless the way we generate corestrings.h, and we force everything to the same context.
+# With line numbers and the similartext heuristic enabled translations can be copied from an old message to a new message,
+# and marked as unfinished.  The threshold for similar is low.
+# These will be used by the application, even though they really need to be checked.
+# Disable the similartext heuristic to avoid these mistranslations.
 qtPrepareTool(LUPDATE, lupdate)
 update.depends = core_strings.h
-update.commands = $$LUPDATE -locations absolute core.pro
+update.commands = $$LUPDATE -disable-heuristic similartext core.pro
 QMAKE_EXTRA_TARGETS += update
 
 qtPrepareTool(LRELEASE, lrelease)
index 7f414846b5ae1819750dfff36beaac92527e2e7f..a0af91be6df889932fab811a1a54ab69e9b612dd 100644 (file)
 #include "appname.h"                       // for appName
 
 
+#ifdef GENERATE_CORE_STRINGS
+extern QTextStream* generate_output_stream;
+#endif
+
 //------------------------------------------------------------------------
 static QString xlt(const QString& f)
 {
 #ifdef GENERATE_CORE_STRINGS
-  qInfo().nospace() << "QT_TRANSLATE_NOOP(\"core\"," << f << ")";
+  *generate_output_stream << "QT_TRANSLATE_NOOP(\"core\",\"" << f << "\")" << Qt::endl;
 #endif
   return QCoreApplication::translate("core", f.toUtf8().constData());
 }